﻿using System.Collections.Generic;
using IQIGame.Onigao.Framework;
using IQIGame.Onigao.GamePlay;

namespace IQIGame.Onigao.Logic
{
    public class BuffEffective
    {
        public void InitProperty(BuffEffectData rData, BuffComponent rTarget)
        {
            this.OnInitProperty(rData, rTarget);
        }

        public void Active(BuffEffectContext rContext, BuffEffectData rConfig, int param)
        {
            this.OnActive(rContext, rConfig, param);
        }

        public void DeActive(BuffEffectContext rContext, BuffEffectData rConfig)
        {
            this.OnDeActive(rContext, rConfig);
        }

        protected virtual void OnInitProperty(BuffEffectData rData, BuffComponent rTarget)
        {
        }

        protected virtual void OnActive(BuffEffectContext rContext, BuffEffectData rConfig, int nRuntimeParam)
        {
        }

        protected virtual void OnDeActive(BuffEffectContext rContext, BuffEffectData rConfig)
        {
        }

#if UNITY_EDITOR
        public virtual string ToString(BuffEffectData rConfig)
        {
            return $"Buff效果:{this.GetType()}";
        }
#endif
    }

    public class BuffEffectiveConfig : IReusableClass
    {
        public uint MaxStore => 2;

        public virtual void OnReset()
        {
        }
    }

    public class BuffEffectContext : IReusableClass
    {
        public BuffHandler buff;

        // 目标，runtimeData 执行结果
        public object result;

        public uint MaxStore => 20;

        public void OnReset()
        {
            this.buff = null;
            this.result = null;
        }
    }

    public class BuffEffectData : IReusableClass
    {
        public EBuffEffectiveType type;
        public BuffEffective effective;
        public int id;
        public List<int> param = new List<int>();
        public List<string> paramStr = new List<string>();
        
        public BuffEffectiveConfig userData;
        public BuffHandler BuffHandle;


        public uint MaxStore => 3;

        public void OnReset()
        {
            this.type = EBuffEffectiveType.Min;
            this.effective = null;
            this.id = 0;
            this.param.Clear();
            this.paramStr.Clear();
            ClassPool.Put(this.userData);
            this.userData = null;
            this.BuffHandle = null;
        }

#if UNITY_EDITOR
        public override string ToString()
        {
            return this.effective?.ToString(this) ?? "NoEffect";
        }
#endif
    }
}